﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Restaurant.DAO;
using Restaurant.DTO;
using System.Data;

namespace Restaurant.BUS
{
    public class DatchoService
    {
        private DatChoDB datChoDAO = new DatChoDB();

        public DataTable LoadDatCho()
        {
            return datChoDAO.LoadDatCho();
        }

        public bool ThemDatCho(DatCho dc)
        {
            if (dc.MaDatCho.ToString() == "" || dc.MaKH.ToString() == "" || dc.NgayDat.ToString() == "" || dc.NgayDen.ToString() == "" || dc.TinhTrang.ToString() == "" || dc.SoLuongNguoi.ToString() == "" || dc.MaNhaHang.ToString() == "")
            {
                return false;
            }
            if (datChoDAO.ThemDatCho(dc.MaKH, dc.NgayDat, dc.NgayDen, dc.TinhTrang, dc.SoLuongNguoi, dc.MaNhaHang))
                return true;
            return false;
        }

        public bool XoaDatCho(int maDatCho, int maKH, int maban)
        {
            if (datChoDAO.XoaDatCho(maDatCho,maKH, maban))
                return true;
            return false;
        }

        public bool SuaDatCho(DatCho dc)
        {
            if (datChoDAO.SuaDatCho(dc.MaDatCho, dc.MaKH, dc.NgayDat, dc.NgayDen, dc.TinhTrang, dc.SoLuongNguoi, dc.MaNhaHang))
                return true;
            return false;
        }

        public DataTable TimChoID(int ma)
        {
            DataTable dbtb = datChoDAO.TimDatChoID(ma);
            return dbtb;
        }

        public DatCho TimChoMaKH(int ma)
        {
            DatCho dc = new DatCho();
            DataTable dbtb = datChoDAO.TimDatChoMaKH(ma);
            DataRow dbrow = dbtb.Rows[0];
            dc.MaDatCho = int.Parse(dbrow[0].ToString());
            dc.MaKH = int.Parse(dbrow[1].ToString());
            dc.NgayDat = DateTime.Parse(dbrow[2].ToString());
            dc.NgayDen = DateTime.Parse(dbrow[3].ToString());
            dc.TinhTrang = int.Parse(dbrow[4].ToString());
            dc.SoLuongNguoi = int.Parse(dbrow[5].ToString());
            dc.MaNhaHang = int.Parse(dbrow[6].ToString());
            return dc;
        }

        public DatCho TimChoTheoNgay(DateTime ngayDat, DateTime ngayDen)
        {
            DatCho dc = new DatCho();
            DataTable dbtb = datChoDAO.TimDatChoNgay(ngayDat, ngayDen);
            DataRow dbrow = dbtb.Rows[0];
            dc.MaDatCho = int.Parse(dbrow[0].ToString());
            dc.MaKH = int.Parse(dbrow[1].ToString());
            dc.NgayDat = DateTime.Parse(dbrow[2].ToString());
            dc.NgayDen = DateTime.Parse(dbrow[3].ToString());
            dc.TinhTrang = int.Parse(dbrow[4].ToString());
            dc.SoLuongNguoi = int.Parse(dbrow[5].ToString());
            dc.MaNhaHang = int.Parse(dbrow[6].ToString());
            return dc;
        }

        public DatCho TimChoMaNH(int ma)
        {
            DatCho dc = new DatCho();
            DataTable dbtb = datChoDAO.TimDatChoMaNH(ma);
            DataRow dbrow = dbtb.Rows[0];
            dc.MaDatCho = int.Parse(dbrow[0].ToString());
            dc.MaKH = int.Parse(dbrow[1].ToString());
            dc.NgayDat = DateTime.Parse(dbrow[2].ToString());
            dc.NgayDen = DateTime.Parse(dbrow[3].ToString());
            dc.TinhTrang = int.Parse(dbrow[4].ToString());
            dc.SoLuongNguoi = int.Parse(dbrow[5].ToString());
            dc.MaNhaHang = int.Parse(dbrow[6].ToString());
            return dc;
        }

        public DatCho TimChoSoLuong(int soLuong)
        {
            DatCho dc = new DatCho();
            DataTable dbtb = datChoDAO.TimDatChoSoLuong(soLuong);
            DataRow dbrow = dbtb.Rows[0];
            dc.MaDatCho = int.Parse(dbrow[0].ToString());
            dc.MaKH = int.Parse(dbrow[1].ToString());
            dc.NgayDat = DateTime.Parse(dbrow[2].ToString());
            dc.NgayDen = DateTime.Parse(dbrow[3].ToString());
            dc.TinhTrang = int.Parse(dbrow[4].ToString());
            dc.SoLuongNguoi = int.Parse(dbrow[5].ToString());
            dc.MaNhaHang = int.Parse(dbrow[6].ToString());
            return dc;
        }

        public DatCho TimChoTinhTrang(string tinhTrang)
        {
            DatCho dc = new DatCho();
            DataTable dbtb = datChoDAO.TimDatChoTinhTrang(tinhTrang);
            DataRow dbrow = dbtb.Rows[0];
            dc.MaDatCho = int.Parse(dbrow[0].ToString());
            dc.MaKH = int.Parse(dbrow[1].ToString());
            dc.NgayDat = DateTime.Parse(dbrow[2].ToString());
            dc.NgayDen = DateTime.Parse(dbrow[3].ToString());
            dc.TinhTrang = int.Parse(dbrow[4].ToString());
            dc.SoLuongNguoi = int.Parse(dbrow[5].ToString());
            dc.MaNhaHang = int.Parse(dbrow[6].ToString());
            return dc;
        }

        public bool ThemCTDatCho(int maDatCho, int maBan)
        {
            if (datChoDAO.ThemCTDatCho(maDatCho, maBan))
                return true;
            return false;
        }

        public DataTable LoadDatChoPhantomError(ref int soluong)
        {
            return datChoDAO.LoadDatChoPhantomError(ref soluong);
        }

        public DataTable LoadDatChoPhantom(ref int soluong)
        {
            return datChoDAO.LoadDatChoPhantom(ref soluong);
        }

        public DataTable LoadDatChoUnrepeatError(ref int soluong)
        {
            return datChoDAO.LoadDatChoUnrepeatError(ref soluong);
        }

        public DataTable LoadDatChoUnrepeat(ref int soluong)
        {
            return datChoDAO.LoadDatChoUnrepeat(ref soluong);
        }
    }

}
